function v_p2() {
	Phaser.State.call(this);
	// TODO: generated method.
}
var proto = Object.create(Phaser.State.prototype);
v_p2.prototype = proto;
v_p2.prototype.constructor = v_p2;

var cp2;
//倒计时
var timerCountDown,timer1,timer2,timer3,CountDownTime = 10;
var subjects,subjectsGroup;
var QuestionsArr,everyQuestionsArr; 
var nextNum = 1;
var FinalScore = 0;
var score1 = 0,score2 = 0,score3 = 0,score4 = 0,score5 = 0;

var mucis_djs;
 
var flg = true;
v_p2.prototype.preload = function() {
	cp2 = new c_p2(this.game);
	cp2.game.load.audio('mucis_djs', 'assets/music/djs.mp3');
	timer1 = this.game.add.text(cp2.fTimrbg.x + 11,cp2.fTimrbg.y - 6,"00",
			{ 
				fill: '#d1bc93',
				fontSize: 56,
				fontWeight: 'bolder',
			}
	);
	timer2 = this.game.add.text(cp2.fTimrbg.x + 78,cp2.fTimrbg.y - 10,":",
			{ 
				fill: '#d1bc93',
				fontSize: 56,
				fontWeight: 'bolder',
			}
	);
	timer3 = this.game.add.text(cp2.fTimrbg.x + 99,cp2.fTimrbg.y - 6,CountDownTime,
			{ 
				fill: '#d1bc93',
				fontSize: 56,
				fontWeight: 'bolder',
			}
	);

	cp2.fPrevq_btn.visible = false;
};
v_p2.prototype.init = function() {
	
};
v_p2.prototype.create = function() {
	mucis_djs = cp2.game.add.audio('mucis_djs');
	subjects = [
	    //0-4
	    {Obj:cp2.fQuestion1,delay_time:0},
	    {Obj:cp2.fQuestion1_1,delay_time:300},
	    {Obj:cp2.fQuestion1_2,delay_time:500},
	    {Obj:cp2.fQuestion1_3,delay_time:700},
	    {Obj:cp2.fQuestion1_4,delay_time:900},
	    //5-9
	    {Obj:cp2.fQuestion2,delay_time:0},
	    {Obj:cp2.fQuestion2_1,delay_time:300},
	    {Obj:cp2.fQuestion2_2,delay_time:500},
	    {Obj:cp2.fQuestion2_3,delay_time:700},
	    {Obj:cp2.fQuestion2_4,delay_time:900},
	    //10-14
	    {Obj:cp2.fQuestion3,delay_time:0},
	    {Obj:cp2.fQuestion3_1,delay_time:300},
	    {Obj:cp2.fQuestion3_2,delay_time:500},
	    {Obj:cp2.fQuestion3_3,delay_time:700},
	    {Obj:cp2.fQuestion3_4,delay_time:900},
	    //15-19
	    {Obj:cp2.fQuestion4,delay_time:0},
	    {Obj:cp2.fQuestion4_1,delay_time:300},
	    {Obj:cp2.fQuestion4_2,delay_time:500},
	    {Obj:cp2.fQuestion4_3,delay_time:700},
	    {Obj:cp2.fQuestion4_4,delay_time:900},
	    //20-24
	    {Obj:cp2.fQuestion5,delay_time:0},
	    {Obj:cp2.fQuestion5_1,delay_time:300},
	    {Obj:cp2.fQuestion5_2,delay_time:500},
	    {Obj:cp2.fQuestion5_3,delay_time:700},
	    {Obj:cp2.fQuestion5_4,delay_time:900},
	];
	subjectsGroup=[
  		{everyGroup:cp2.fQuestion1group},
  		{everyGroup:cp2.fQuestion2group},
  		{everyGroup:cp2.fQuestion3group},
  		{everyGroup:cp2.fQuestion4group},
  		{everyGroup:cp2.fQuestion5group},
    ];
	QuestionsArr = 
		{
			question1:{
				groupName: cp2.fQuestion1group, subject: cp2.fQuestion1, 
				answerA: cp2.fQuestion1_1, answerB: cp2.fQuestion1_2, answerC:cp2.fQuestion1_3, answerD:cp2.fQuestion1_4,
				answerAOn: 'question1_1_on', answerBOn: 'question1_2_on', answerCOn:'question1_3_on', answerDOn:'question1_4_on',
				answerAOff: 'question1_1', answerBOff: 'question1_2', answerCOff:'question1_3', answerDOff:'question1_4',
				scoreA:0,scoreB:0,scoreC:20,scoreD:0
			},
			question2:{
				groupName: cp2.fQuestion2group, subject: cp2.fQuestion2, 
				answerA: cp2.fQuestion2_1, answerB: cp2.fQuestion2_2, answerC:cp2.fQuestion2_3, answerD:cp2.fQuestion2_4,
				answerAOn: 'question2_1_on', answerBOn: 'question2_2_on', answerCOn:'question2_3_on', answerDOn:'question2_4_on',
				answerAOff: 'question2_1', answerBOff: 'question2_2', answerCOff:'question2_3', answerDOff:'question2_4',
				scoreA:20,scoreB:0,scoreC:0,scoreD:0
			},
			question3:{
				groupName: cp2.fQuestion3group, subject: cp2.fQuestion3, 
				answerA: cp2.fQuestion3_1, answerB: cp2.fQuestion3_2, answerC:cp2.fQuestion3_3, answerD:cp2.fQuestion3_4,
				answerAOn: 'question3_1_on', answerBOn: 'question3_2_on', answerCOn:'question3_3_on', answerDOn:'question3_4_on',
				answerAOff: 'question3_1', answerBOff: 'question3_2', answerCOff:'question3_3', answerDOff:'question3_4',
				scoreA:0,scoreB:0,scoreC:0,scoreD:20
			},
			question4:{
				groupName: cp2.fQuestion4group, subject: cp2.fQuestion4,
				answerA: cp2.fQuestion4_1, answerB: cp2.fQuestion4_2, answerC:cp2.fQuestion4_3, answerD:cp2.fQuestion4_4,
				answerAOn: 'question4_1_on', answerBOn: 'question4_2_on', answerCOn: 'question4_3_on', answerDOn: 'question4_4_on',
				answerAOff: 'question4_1', answerBOff: 'question4_2', answerCOff:'question4_3', answerDOff:'question4_4',
				scoreA:20,scoreB:0,scoreC:0,scoreD:0
			},
			question5:{
				groupName: cp2.fQuestion5group, subject: cp2.fQuestion5,
				answerA: cp2.fQuestion5_1, answerB: cp2.fQuestion5_2, answerC:cp2.fQuestion5_3, answerD:cp2.fQuestion5_4,
				answerAOn: 'question5_1_on', answerBOn: 'question5_2_on', answerCOn: 'question5_3_on', answerDOn:'question5_4_on',
				answerAOff: 'question5_1', answerBOff: 'question5_2', answerCOff:'question5_3', answerDOff:'question5_4',
				scoreA:0,scoreB:0,scoreC:0,scoreD:20
			}
		};
	everyQuestionsArr = Object.getOwnPropertyNames(QuestionsArr);

	
	animation(nextNum);
	
	cp2.fNextq_btn.inputEnabled = true;
	cp2.fNextq_btn.events.onInputDown.add(function(){
		timer3.text = "10";
		//console.log(nextNum);
		clearInterval(timerCountDown);
		animation(nextNum+1);
		nextNum = nextNum+1;
		if(nextNum == 5){
			nextNum = 5;
			//console.log("result");
		}
	});
	
	cp2.fPrevq_btn.inputEnabled = true;
	cp2.fPrevq_btn.events.onInputDown.add(function(){
		timer3.text = "10";
		clearInterval(timerCountDown);
		animation(nextNum-1);
		nextNum = nextNum-1;
		if(nextNum == 1){
			nextNum = 1;
			var nextBtnTw_1 = cp2.game.add.tween(cp2.fNextq_btn);
			nextBtnTw_1.to({x:212},700,Phaser.Easing.Linear.In,true,0,0,false);
			cp2.fPrevq_btn.visible = false;
			
		}
		cp2.fNextq_btn.loadTexture('nextq_btn',0,true);
		//console.log(nextNum);
	});
	
	
	cp2.fResult_btn.events.onInputDown.add(function () {
	    clearInterval(timerCountDown);
	    FinalScore = score1 + score2 + score3 + score4 + score5;



	    if (flg == false) {
	        return;
	    }
	    flg = false;
	    $.ajax({
	        url: "/17720_RIRiSun1/H_Action/H_Action.ashx?action=UPUser&t=" + new Date().getTime(),
	        type: "post",
	        data: { score: FinalScore },
	        success: function (data) {
	            flg = true;
	            cp2.game.view.show('v_p3');
	            mucis_djs.stop();
	        }
	    });





		//cp2.game.view.show('v_p3');
		//mucis_djs.stop();
	});
};
v_p2.prototype.update = function() {
	//console.log(score1+"__"+score2+"__"+score3+"__"+score4+"__"+score5);
};
function restartInterval(){
	timer3.text = "10";
	CountDownTime = 10;
	mucis_djs.play();
	timerCountDown = setInterval(function(){
		if(CountDownTime <= 0){
			clearInterval(timerCountDown);
			nextNum++;
			if(nextNum > 5){
				nextNum = 5;
				cp2.fResult_btn.inputEnabled = false;
				clearInterval(timerCountDown);
				FinalScore = score1 + score2 + score3 + score4 + score5;



				if (flg == false) {
				    return;
				}
				flg = false;
				$.ajax({
				    url: "/17720_RIRiSun1/H_Action/H_Action.ashx?action=UPUser&t=" + new Date().getTime(),
				    type: "post",
				    data: { score: FinalScore },
				    success: function (data) {
				        flg = true;
				        cp2.game.view.show('v_p3');
				        mucis_djs.stop();
				        clearInterval(timerCountDown);

				    }
				});


				//cp2.game.view.show('v_p3');
				//mucis_djs.stop();
			}else{
				animation(nextNum);
			}
			
		}else{
			CountDownTime--;
			if(CountDownTime.toString().length < 2){
				timer3.text = "0"+CountDownTime;
			}else{
				timer3.text = CountDownTime;
			}
		}
	},1000);
}
function animation(subjectIndex){
	restartInterval();
	//汽车的效果
	var carTw1 = cp2.game.add.tween(cp2.fCar);
	carTw1.to({angle:0,alpha:1,x:52,y:918},1000,Phaser.Easing.Linear.In,false,0,0,false);
	
	var carTw2 = cp2.game.add.tween(cp2.fCar);
	carTw2.to({angle:0,x:207,y:921},1000,Phaser.Easing.Linear.In,false,0,0,false);
	
	var carTw3_1 = cp2.game.add.tween(cp2.fCar);
	var carTw3_2 = cp2.game.add.tween(cp2.fCar);
	carTw3_1.to({angle:0,x:275,y:914},500,Phaser.Easing.Linear.In,false,0,0,false).onComplete.addOnce(function(){
		carTw3_2.to({angle:0,x:332,y:931},500,Phaser.Easing.Linear.In,true,0,0,false);
	});
	
	var carTw4_1 = cp2.game.add.tween(cp2.fCar);
	var carTw4_2 = cp2.game.add.tween(cp2.fCar);
	carTw4_1.to({x:395,y:943},500,Phaser.Easing.Linear.In,false,0,0,false).onComplete.addOnce(function(){
		carTw4_2.to({angle:-19,x:445,y:921},500,Phaser.Easing.Linear.In,true,0,0,false);
	});
	
	var carTw5_1 = cp2.game.add.tween(cp2.fCar);
	var carTw5_2 = cp2.game.add.tween(cp2.fCar);
	var carTw5_3 = cp2.game.add.tween(cp2.fCar);
	carTw5_1.to({x:474,y:902},300,Phaser.Easing.Linear.In,false,0,0,false).onComplete.addOnce(function(){
		carTw5_2.to({angle:10,x:543,y:929},700,Phaser.Easing.Linear.In,true,0,0,false).onComplete.addOnce(function(){
			carTw5_3.to({angle:0,x:550,y:929},700,Phaser.Easing.Linear.In,true,0,0,false);
		});
	});
	//按钮
	var nextBtnTw = cp2.game.add.tween(cp2.fNextq_btn);
	nextBtnTw.to({x:345},700,Phaser.Easing.Linear.In,false,0,0,false);
	var prevBtnTw = cp2.game.add.tween(cp2.fPrevq_btn);
	prevBtnTw.to({x:70},700,Phaser.Easing.Linear.In,false,0,0,false);
   	function groupVisible(){
   		
   		
   	   	for(var i = 0; i < 5; i++){
   	   		if(i == subjectIndex-1){
   	   			subjectsGroup[subjectIndex-1].everyGroup.visible = true;
   	   			
   	   			QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerA.inputEnabled = true;
   	   			QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerB.inputEnabled = true;
   	   			QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerC.inputEnabled = true;
   	   			QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerD.inputEnabled = true;
   	   			
   	   		}else{
   	   			subjectsGroup[i].everyGroup.visible = false;
   	   			QuestionsArr[everyQuestionsArr[i]].answerA.inputEnabled = false;
	   			QuestionsArr[everyQuestionsArr[i]].answerB.inputEnabled = false;
	   			QuestionsArr[everyQuestionsArr[i]].answerC.inputEnabled = false;
	   			QuestionsArr[everyQuestionsArr[i]].answerD.inputEnabled = false;
   	   		}
   	   	}
   	}
	//0-4
	if(subjectIndex == 1){
		groupVisible();
		carTw1.start();
		for(var i = 0; i < 5; i++){
			var subject1Tw;
			if(i == 0){
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0
				},500,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}else{
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0,
					x:75,
				},300,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}
		}
	}
	
	//5-9
	else if(subjectIndex == 2){
		groupVisible();
		carTw2.start();
		cp2.fPrevq_btn.visible = true;
		prevBtnTw.start();
		nextBtnTw.start();
		for(var i = 5;i < 10; i++){
			var subject1Tw;
			if(i == 5){
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0
				},500,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}else{
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0,
					x:70,
				},300,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}
		}
	}
	
	//10-14
	else if(subjectIndex == 3){
		groupVisible();
		carTw3_1.start();
		for(var i = 10;i < 15; i++){
			var subject1Tw;
			if(i == 10){
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0
				},500,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}else{
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0,
					x:65,
				},300,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}
		}
	}
	
	//15-19
	else if(subjectIndex == 4){
		groupVisible();
		carTw4_1.start();
		for(var i = 15;i < 20; i++){
			var subject1Tw;
			if(i == 15){
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0
				},500,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}else{
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0,
					x:60,
				},300,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}
		}
		cp2.fNextq_btn.inputEnabled = true;
		cp2.fNextq_btn.alpha = 1;
		cp2.fResult_btn.inputEnabled = false;
	}
	
	//20-24
	else if(subjectIndex == 5){
		groupVisible();
		carTw5_1.start();
		cp2.fNextq_btn.loadTexture('result_btn',0,true);
		cp2.fNextq_btn.inputEnabled = false;
		cp2.fResult_btn.inputEnabled = true;
		cp2.fNextq_btn.alpha = 0;
		for(var i = 20;i < 25; i++){
			var subject1Tw;
			if(i == 20){
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0
				},500,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}else{
				subject1Tw = cp2.game.add.tween(subjects[i].Obj);
				subject1Tw.from({
					alpha:0,
					x:60,
				},300,Phaser.Easing.Linear.In,true,subjects[i].delay_time,0,false);
			}
		}
	}
	
	//A
	QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerA.events.onInputDown.add(function(item){
		
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerB.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerBOff,0,true);
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerC.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerCOff,0,true);
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerD.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerDOff,0,true);
		item.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerAOn,0,true);
		
		if(subjectIndex == 1){
			score1 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreA;
		}else if(subjectIndex == 2){
			score2 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreA;
		}else if(subjectIndex == 3){
			score3 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreA;
		}else if(subjectIndex == 4){
			score4 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreA;
		}else if(subjectIndex == 5){
			score5 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreA;
		}
		
	});
	
	//B
	QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerB.events.onInputDown.add(function(item){
		
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerA.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerAOff,0,true);
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerC.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerCOff,0,true);
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerD.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerDOff,0,true);
		item.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerBOn,0,true);
		
		if(subjectIndex == 1){
			score1 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreB;
		}else if(subjectIndex == 2){
			score2 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreB;
		}else if(subjectIndex == 3){
			score3 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreB;
		}else if(subjectIndex == 4){
			score4 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreB;
		}else if(subjectIndex == 5){
			score5 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreB;
		}
	});
	//C
	QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerC.events.onInputDown.add(function(item){
		
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerA.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerAOff,0,true);
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerB.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerBOff,0,true);
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerD.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerDOff,0,true);
		item.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerCOn,0,true);

		if(subjectIndex == 1){
			score1 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreC;
		}else if(subjectIndex == 2){
			score2 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreC;
		}else if(subjectIndex == 3){
			score3 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreC;
		}else if(subjectIndex == 4){
			score4 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreC;
		}else if(subjectIndex == 5){
			score5 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreC;
		}
	});
	//D
	QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerD.events.onInputDown.add(function(item){
		
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerB.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerBOff,0,true);
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerC.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerCOff,0,true);
		QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerA.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerAOff,0,true);
		item.loadTexture(QuestionsArr[everyQuestionsArr[subjectIndex-1]].answerDOn,0,true);

		if(subjectIndex == 1){
			score1 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreD;
		}else if(subjectIndex == 2){
			score2 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreD;
		}else if(subjectIndex == 3){
			score3 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreD;
		}else if(subjectIndex == 4){
			score4 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreD;
		}else if(subjectIndex == 5){
			score5 = QuestionsArr[everyQuestionsArr[subjectIndex-1]].scoreD;
		}
	});
}

